home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- // Description:
- // Go through all shaders in the scene, find the file texture nodes directly connected
- // to the color attribute. For each file texture connected to the color attribute, we
- // connect the outTransparency too if and only if:
- //
- // - There isn't anything connected to the shader's transparency attribute.
- // - The file texture contains some transparent pixels (ie: fileTexture.fileHasAlpha == 1)
- //
- global proc useTextureAlphasForTransparency()
- {
- string $materials[];
-
- // Get a list of all material nodes in the scene
- //
- $materials = `ls -materials`;
-
- int $i;
-
- for ($i = 0; $i < size($materials); $i++)
- {
- if ( (size(`ls ($materials[$i] + ".color")`) != 0)
- && (size(`ls ($materials[$i] + ".transparency")`) != 0))
- {
- //
- // The material has color and transparency attributes
- //
-
- // Determine the source node of the color attribute of the material
- // (if any)
- //
- string $colorSrc[];
-
- $colorSrc =
- `listConnections
- -source true
- -destination false
- ($materials[$i] + ".color")`;
-
- // Determine the source node of the transparency attribute of the
- // material (if any)
- //
- string $transparencySrc[];
-
- $transparencySrc =
- `listConnections
- -source true
- -destination false
- ($materials[$i] + ".transparency")`;
-
- string $colorTextureName = $colorSrc[0];
- int $fileHasAlpha = ($colorTextureName != "")
- && (`nodeType $colorTextureName` == "file")
- && (`getAttr ($colorTextureName+".fileHasAlpha")`);
-
-
- if ($fileHasAlpha && ($colorSrc[0] != "") && ($transparencySrc[0] == ""))
- {
- //
- // The color attribute has a source node, and the transparency
- // attribute doesn't
- //
-
- if (size(`ls ($colorSrc[0] + ".outTransparency")`) != 0)
- {
- // The source node of the color attribute of the material
- // also has an outTransparency attribute, so we will
- // connect it to the transparency attribute of the
- // material.
- //
- connectAttr
- ($colorSrc[0] + ".outTransparency")
- ($materials[$i] + ".transparency");
- }
- }
- }
- }
- }
-